package com.duowei.dw_pos.application;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.support.multidex.MultiDex;

import com.duowei.dw_pos.BuildConfig;
import com.duowei.dw_pos.bean.DMJYXMSSLB;
import com.duowei.dw_pos.httputils.MyVolley;
import com.duowei.dw_pos.httputils.NetUtils;
import com.duowei.dw_pos.tools.DataLoad;
import com.tencent.bugly.crashreport.CrashReport;

import net.danlew.android.joda.JodaTimeAndroid;

import org.litepal.LitePalApplication;
import org.litepal.crud.DataSupport;

import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;

/**
 * Created by Administrator on 2017-03-21.
 */

public class MyApplication extends LitePalApplication {
    public static Context mContext;
    @Override
    public void onCreate() {
        super.onCreate();
        mContext=this;

        MyVolley.init(this);
        JodaTimeAndroid.init(this);
        NetUtils.init();
        MultiDex.install(this);
        CrashReport.initCrashReport(getApplicationContext(), "09ddd38eb1", BuildConfig.DEBUG);
        CrashReport.putUserData(getApplicationContext(), "MAC", getMacAddress());
        if (Build.VERSION.SDK_INT>=28) {
            closeAndroidPDialog();
        }
    }

    @SuppressLint("HardwareIds")
    private String getMacAddress() {
        WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        WifiInfo info = manager.getConnectionInfo();
        return info.getMacAddress();
    }

    private void closeAndroidPDialog(){
        try {
            Class aClass = Class.forName("android.content.pm.PackageParser$Package");
            Constructor declaredConstructor = aClass.getDeclaredConstructor(String.class);
            declaredConstructor.setAccessible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            Class cls = Class.forName("android.app.ActivityThread");
            Method declaredMethod = cls.getDeclaredMethod("currentActivityThread");
            declaredMethod.setAccessible(true);
            Object activityThread = declaredMethod.invoke(null);
            Field mHiddenApiWarningShown = cls.getDeclaredField("mHiddenApiWarningShown");
            mHiddenApiWarningShown.setAccessible(true);
            mHiddenApiWarningShown.setBoolean(activityThread, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
